home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE23 / STARTUP / StubExeU.pas < prev    next >
Pascal/Delphi Source File  |  1996-03-20  |  2KB  |  73 lines

  1. unit stubexeu;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinProcs, WinTypes, Messages, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     LoadLibBtn: TButton;
  12.     FreeLibBtn: TButton;
  13.     procedure LoadLibBtnClick(Sender: TObject);
  14.     procedure FreeLibBtnClick(Sender: TObject);
  15.   private
  16.     { Private declarations }
  17.   public
  18.     { Public declarations }
  19.     DllLib: THandle;
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TForm1.LoadLibBtnClick(Sender: TObject);
  30. begin
  31.   OutputDebugString('APP: "Load Library" button pressed'#13#10);
  32.   DllLib := LoadLibrary('stubdll.dll');
  33.   if DllLib <> 0 then
  34.   begin
  35.     LoadLibBtn.Enabled := False;
  36.     FreeLibBtn.Enabled := True;
  37.   end
  38.   else
  39.     raise EFOpenError.Create('No StubDll');
  40. end;
  41.  
  42. procedure TForm1.FreeLibBtnClick(Sender: TObject);
  43. begin
  44.   OutputDebugString('APP: "Free Library" button pressed'#13#10);
  45.   if DllLib <> 0 then
  46.   begin
  47.     FreeLibrary(DllLib);
  48.     LoadLibBtn.Enabled := True;
  49.     FreeLibBtn.Enabled := False;
  50.   end;
  51. end;
  52.  
  53. var
  54.   OldExitProc: Pointer;
  55.  
  56. procedure NewExitProc; far;
  57. begin
  58.   ExitProc := OldExitProc;
  59.   OutputDebugString('APP: Exit procedure added the old fashioned way (ExitProc)'#13#10);
  60. end;
  61.  
  62. procedure NewerExitProc; far;
  63. begin
  64.   OutputDebugString('APP: Exit procedure added with AddExitProc'#13#10);
  65. end;
  66.  
  67. initialization
  68.   OutputDebugString('APP: Unit initialisation section'#13#10);
  69.   OldExitProc := ExitProc;
  70.   ExitProc := @NewExitProc;
  71.   AddExitProc(NewerExitProc);
  72. end.
  73.